package com.star.warmwinter.module.home.viewCtrl;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.media.MediaPlayer;
import android.net.Uri;
import android.view.View;

import com.star.warmwinter.R;
import com.star.warmwinter.databinding.ActivitySplashBinding;
import com.star.warmwinter.module.user.ui.LoginIndexActivity;

import java.util.Date;

/**
 * 项目名称：WarmWinter
 * 类描述：
 * 创建人：Johnny
 * 创建时间：2018/6/6 16:41
 */
public class SplashCtrl {

    private Activity mActivity;
    private ActivitySplashBinding mBinding;

    public SplashCtrl(Activity activity, ActivitySplashBinding mBinding) {
        this.mActivity = activity;
        this.mBinding = mBinding;
    }

    public void playVideo() {
        int hour = new Date().getHours();
        if (hour > 5 && hour < 18) {
            mBinding.videoView.setVideoURI(Uri.parse("android.resource://" + mActivity.getPackageName() + "/" + R.raw.loading_white));
            mBinding.textPass.setTextColor(mActivity.getResources().getColor(R.color.white));
            mBinding.textPass.setBackgroundResource(R.drawable.circle_white_bg);
        } else {
            mBinding.videoView.setVideoURI(Uri.parse("android.resource://" + mActivity.getPackageName() + "/" + R.raw.loading_dark));
            mBinding.textPass.setTextColor(mActivity.getResources().getColor(R.color.color_A99BDA));
            mBinding.textPass.setBackgroundResource(R.drawable.circle_white_bg);
        }
        mBinding.videoView.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
            @Override
            public void onCompletion(MediaPlayer mp) {
                onPass(null);
            }
        });
        mBinding.videoView.start();
    }

    public void onPass(View view){
        Intent intent = new Intent(mActivity, LoginIndexActivity.class);
        mActivity.startActivity(intent);
        mActivity.finish();
    }

}
